package com.oocl.hw02.scene;

import com.oocl.hw02.sprint.BasicSprint;
import com.oocl.hw02.sprint.Plant;

public class MainScene {

    private final int ROW_COUNT = 6;
    private final int COL_COUNT = 9;

    private int sunCount;
    private BasicSprint[][] map;

    public MainScene() {
        this.sunCount = 0;
        this.map = new BasicSprint[ROW_COUNT][COL_COUNT];
    }

    public int getSunCount() {
        return sunCount;
    }

    public void setSunCount(int sunCount) {
        this.sunCount = sunCount;
    }

    public void addSprintToLocation(int row, int col, BasicSprint sprint) throws Exception {
        if (row < 0 || row >= ROW_COUNT || col < 0 || col >= COL_COUNT) {
            throw new Exception("Out of bound!");
        }

        // when adding a plant, check if sun count enough
        if (sprint instanceof Plant) {
            int sunCost = ((Plant) sprint).getSunCost();
            if (sunCost > this.sunCount) {
                throw new Exception("Sun not enough!");
            }
            this.sunCount -= sunCost;
        }

        map[row][col] = sprint;
    }
}
